# 主程序和附加头文件
file(GLOB MAIN_SRC CONFIGURE_DEPENDS *.cpp *.hpp)
file(GLOB MAIN_INC CONFIGURE_DEPENDS *.h)
include_directories(.)

# 封装程序
file(GLOB GL_SRC CONFIGURE_DEPENDS GLProgram/*.cpp)
file(GLOB GL_INC CONFIGURE_DEPENDS GLProgram/*.h)

source_group(GLProgram FILES ${GL_SRC} ${GL_INC})
include_directories(GLProgram)

# 封装程序
file(GLOB KIT_SRC CONFIGURE_DEPENDS Kit/*.cpp)
file(GLOB KIT_INC CONFIGURE_DEPENDS Kit/*.h)

source_group(Kit FILES ${KIT_SRC} ${KIT_INC})
include_directories(Kit)

# LSCM
file(GLOB LSCM_SRC CONFIGURE_DEPENDS LSCM/*.cpp)
file(GLOB LSCM_INC CONFIGURE_DEPENDS LSCM/*.h)

source_group(LSCM FILES ${LSCM_SRC} ${LSCM_INC})
include_directories(LSCM)

# ARAP
file(GLOB ARAP_SRC CONFIGURE_DEPENDS ARAP/*.cpp)
file(GLOB ARAP_INC CONFIGURE_DEPENDS ARAP/*.h)

source_group(ARAP FILES ${ARAP_SRC} ${ARAP_INC})
include_directories(ARAP)

# Para
file(GLOB PARA_SRC CONFIGURE_DEPENDS Para/*.cpp)
file(GLOB PARA_INC CONFIGURE_DEPENDS Para/*.h)

source_group(Para FILES ${PARA_SRC} ${PARA_INC})
include_directories(Para)

# OpenMesh
set(OPENMESH_LIBRARY_DIR "D:/lib/OpenMesh-10.0/lib")
set(OPENMESH_INCLUDE_DIR "D:/lib/OpenMesh-10.0/include")
include_directories(${OPENMESH_INCLUDE_DIR})

# 添加编译定义
set_property(
  DIRECTORY
  APPEND
  PROPERTY COMPILE_DEFINITIONS _USE_MATH_DEFINES)

# Eigen
set(Eigen3_DIR "D:/lib/Eigen3/share/eigen3/cmake")
find_package(Eigen3 REQUIRED)

if((Eigen3_FOUND) AND (DEFINED EIGEN3_INCLUDE_DIR))
  message(STATUS "Found Eigen3: " ${EIGEN3_INCLUDE_DIR})
  include_directories(${EIGEN3_INCLUDE_DIR})
else()
  message(FATAL_ERROR "EIGEN3 not found.")
endif()

# 通过 find 获得 OCC
set(OPENCASCADE_DIR D:/lib/OpenCASCADE-7.4.0-vc14-64/opencascade-7.4.0/cmake)
find_package(OPENCASCADE REQUIRED)

# 引入 OCC 头文件路径，库文件路径
include_directories(${OpenCASCADE_INCLUDE_DIR})
link_directories(${OpenCASCADE_LIBRARY_DIR})

# 引入资源配置
include(D:/lib/CMakeRC/CMakeRC.cmake)
file(GLOB SHADER CONFIGURE_DEPENDS Shader/*.vert Shader/*.geom Shader/*.frag)

# 添加资源文件，命名为 Shader 空间中的 rc
cmrc_add_resource_library(ShaderLib ALIAS Shader::rc NAMESPACE Shader)
cmrc_add_resources(ShaderLib WHENCE Shader ${SHADER})

include_directories(GLProgram D:/lib/OpenGL/include D:/lib/stb_image D:/lib/glm)
link_directories(D:/lib/OpenGL/lib)

# 将 glad.c 加入项目
add_executable(
  main
  D:/lib/OpenGL/glad.c
  ${MAIN_SRC}
  ${MAIN_INC}
  ${GL_SRC}
  ${GL_INC}
  ${KIT_SRC}
  ${KIT_INC}
  ${LSCM_SRC}
  ${LSCM_INC}
  ${ARAP_SRC}
  ${ARAP_INC}
  ${PARA_SRC}
  ${PARA_INC})

# 链接 OCC 的全部静态库
foreach(LIB ${OpenCASCADE_LIBRARIES})
  target_link_libraries(main PRIVATE debug ${LIB}.lib)
  target_link_libraries(main PRIVATE optimized ${LIB}.lib)
endforeach(LIB ${OpenCASCADE_LIBRARIES})

# 链接静态库
target_link_libraries(main PRIVATE debug Shader::rc opengl32.lib glfw3.lib)
target_link_libraries(main PRIVATE optimized Shader::rc opengl32.lib glfw3.lib)

# 对不同模式指定静态库
target_link_libraries(main PRIVATE debug
                                   ${OPENMESH_LIBRARY_DIR}/OpenMeshCored.lib)
target_link_libraries(main PRIVATE debug
                                   ${OPENMESH_LIBRARY_DIR}/OpenMeshToolsd.lib)
target_link_libraries(main PRIVATE optimized
                                   ${OPENMESH_LIBRARY_DIR}/OpenMeshCore.lib)
target_link_libraries(main PRIVATE optimized
                                   ${OPENMESH_LIBRARY_DIR}/OpenMeshTools.lib)

set(DLL_PATH1
    "D:/lib/OpenCASCADE-7.4.0-vc14-64/opencascade-7.4.0/win64/vc14/bin")
set(DLL_PATH2 "D:/lib/OpenCASCADE-7.4.0-vc14-64/freetype-2.5.5-vc14-64/bin")
set(DLL_PATH3 "D:/lib/OpenCASCADE-7.4.0-vc14-64/freeimage-3.17.0-vc14-64/bin")
set(DLL_PATH4 "D:/lib/OpenCASCADE-7.4.0-vc14-64/ffmpeg-3.3.4-64/bin")
set(DLL_PATH5
    "D:/lib/OpenCASCADE-7.4.0-vc14-64/tbb_2017.0.100/bin/intel64/vc14")
set(DLL_PATH6 "D:/lib/OpenMesh-10.0")
set(DLL_PATH
    "PATH=${DLL_PATH1}\;${DLL_PATH2}\;${DLL_PATH3}\;${DLL_PATH4}\;${DLL_PATH5}\;${DLL_PATH6}\;%PATH%"
)

set_target_properties(main PROPERTIES VS_DEBUGGER_ENVIRONMENT ${DLL_PATH})
